package org.icdio.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.icdio.dao.User;
import org.icdio.dao.impl.UserImpl;
import org.icdio.entity.SimpleUser;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class Test
 */
@WebServlet("/Test")
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Test() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
	
		String req = request.getParameter("inputData");
		User user = new UserImpl();
		JSONObject jsonObject = new JSONObject();
		SimpleUser simpleUser = user.selectById(Integer.parseInt(req));
		jsonObject.put("id", simpleUser.getId());
		jsonObject.put("userId", simpleUser.getUserId());
		jsonObject.put("userName", simpleUser.getUserName());
		jsonObject.put("password", simpleUser.getPassword());
		jsonObject.put("createTime", simpleUser.getCreateTime());
		System.out.println("获取到的数据："+jsonObject.toString());
		response.getWriter().write(jsonObject.toString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
